package cn.ekuma.beans;
import java.awt.BorderLayout;
import java.awt.Font;
import javax.swing.*;

public class Test {

    public static final Font DEFAULT_FONT = new Font("微软雅黑", Font.BOLD, 14);
    public static final Font TABLE_FONT = new Font("微软雅黑", Font.BOLD, 12);
    public static final Font TITLE_FONT = new Font("微软雅黑", Font.BOLD, 50);

    public static void main(String[] args) {
        UIManager.put("Label.font", DEFAULT_FONT);
        UIManager.put("TableHeader.font", DEFAULT_FONT);

        JTable table = new JTable(5, 4);
        table.getColumnModel().getColumn(0).setHeaderValue("摘要");
        table.getColumnModel().getColumn(1).setHeaderValue("会计科目");
        table.getColumnModel().getColumn(2).setHeaderValue("借方金额");
        table.getColumnModel().getColumn(2).setCellRenderer(new MoneyRenderer());
        table.getColumnModel().getColumn(2).setCellEditor(new MoneyEditor());
        table.getColumnModel().getColumn(3).setHeaderValue("贷方金额");
        table.getColumnModel().getColumn(3).setCellRenderer(new MoneyRenderer());
        table.getColumnModel().getColumn(3).setCellEditor(new MoneyEditor());
        table.setRowHeight(30);
        table.setValueAt("采购商品", 0, 0);
        table.setValueAt("1406 - 库存商品", 0, 1);
        table.setValueAt("10000", 0, 2);
        table.setValueAt("22218001001 - 应缴税费-应缴增值税-进项税额", 1, 1);
        table.setValueAt("1700", 1, 2);
        table.setValueAt("1002 - 银行存款", 2, 1);
        table.setValueAt("11700", 2, 3);
        table.setValueAt("合计", 4, 0);
        table.setValueAt("11700", 4, 2);
        table.setValueAt("11700", 4, 3);
        table.setFont(TABLE_FONT);
        table.getColumnModel().getColumn(1).setPreferredWidth(250);

        JFrame frame = new JFrame();
        JLabel lbTitle = new JLabel("记账凭证");
        lbTitle.setHorizontalAlignment(SwingConstants.CENTER);
        lbTitle.setFont(TITLE_FONT);
        frame.add(lbTitle, BorderLayout.NORTH);
        JScrollPane scroll = new JScrollPane(table);
        scroll.setBorder(null);
        table.setBorder(null);
        frame.add(scroll, BorderLayout.CENTER);
        ((JPanel) frame.getContentPane()).setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(800, 500);
        frame.setLocation(300, 300);
        frame.setTitle("中国式凭证录入");
        frame.setVisible(true);
    }
}
